package com.chief.mybatisplus;

import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chief.MybatisPulsTestService;
import jdk.nashorn.internal.runtime.QuotedStringTokenizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.jsf.el.WebApplicationContextFacesELResolver;

import java.util.List;
import java.util.function.Consumer;

@RestController
public class MyBatisPlusTestServiceImpl implements MybatisPulsTestService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public String test() {

        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("name","22222").orderByDesc("name");

        List<User> users = this.userMapper.selectList(wrapper);
        System.out.println("1=====================");
        for (User user : users) {
            System.out.println(user.toString());
        }

        users = this.userMapper.selectList(null);
        System.out.println("2=====================");
        for (User user : users) {
            System.out.println(user.toString());
        }

        Page<User> page= this.userMapper.selectPage(new Page<User>(1,1),
                new QueryWrapper<User>().likeRight("name","2"));
        System.out.println("3=====================");
        for (User user : page.getRecords()) {
            System.out.println(user.toString());
        }

        users = this.userMapper.getUser();
        System.out.println("4=====================");
        for (User user : users) {
            System.out.println(user.toString());
        }

        wrapper = new QueryWrapper<>();
        wrapper.apply("sex={0} and name like {1}",1,"%2%");
        users = this.userMapper.selectList(wrapper);
        System.out.println("5=====================");
        for (User user : users) {
            System.out.println(user.toString());
        }




        this.userMapper.deleteById(1);
        users = this.userMapper.selectList(null);
        System.out.println("6=====================");
        for (User user : users) {
            System.out.println(user.toString());
        }
        return JSONArray.of(users).toString();
    }


}

